function out=fobj(w,xi)
% w=randn(dim*3+3,1);
% xi=30;
load fisheriris;


X = meas;[num,dim]=size(X);
y=ones(dim,1);
for i=1:num
    if strcmp(species{i},'setosa')
        y(i) =1;
    elseif strcmp(species{i},'versicolor')
        y(i) =2;
    else
        y(i)=3;
    end
end

C=max(max(abs(X)))*10;

out= norm(w)^2/2;

idx=y(xi);


for j=1:3
    if  j==idx
        out=out+C*pos(1-(X(xi,:)*w(1+(j-1):dim*j)-w(dim*3+j)));
    else
        out=out+C*pos(1+(X(xi,:)*w(1+(j-1):dim*j)-w(dim*3+j)));
    end
end
